package com.changgou.order.service.impl;


import com.changgou.goods.feign.GoodsFeign;
import com.changgou.goods.pojo.Sku;
import com.changgou.order.dao.MyCollectionMapper;
import com.changgou.order.service.MyCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class MyCollectionServiceImpl implements MyCollectionService {

    @Autowired
    private MyCollectionMapper mycollectionMapper;
    @Autowired
    private GoodsFeign goodsFeign;
    /**
     * 我的收藏
     * @param username
     * @return
     */
    @Override
    public List<Sku> findByUsername(String username) {
        List<Long> Ids = mycollectionMapper.findSkuIds(username);
        ArrayList<Sku> skus = new ArrayList<>();
        for (Long id : Ids) {
            Sku sku = goodsFeign.findById(String.valueOf(id)).getData();
            skus.add(sku);
        }
        return skus;
    }

    /**
     * 查询收藏数
     * @param username
     * @return
     */
    @Override
    public Integer findByIdCount(String username) {
        Integer byCount = mycollectionMapper.SkuByCount(username);
        return byCount;
    }


}
